<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>定呗</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="alternate icon" type="image/png" href="__PUBLIC__/assets/i/46.png">
    <link rel="stylesheet" href="__PUBLIC__/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="__PUBLIC__/assets/css/app.css">
    <link rel="stylesheet" href="__PUBLIC__/css/pub.css">
    <link rel="stylesheet" href="__PUBLIC__/css/dici.css">
    <style>
        .header {
            text-align: center;
        }

        .header h1 {
            font-size: 200%;
            color: #333;
            margin-top: 30px;
        }

        .header p {
            font-size: 14px;
        }

        .w-span2 {
            display: none;
        }

        .w-span3 {
            display: none;
        }
    </style>
</head>
<body class="login">
<div class="header">
    <hr/>
</div>
<div class="am-g">
    <div class="am-u-lg-6 am-u-md-8 am-u-sm-centered">
        <h2>
            <img src="__PUBLIC__/images/logo.png" style="width: 200px;"/>
            <span>商家注册</span>
        </h2>
        <hr>
        <div class="am-input-group">
            <span class="am-input-group-label"><i class="am-icon-user am-icon-fw"></i></span>
            <input type="text" name="phone" id="phone" placeholder="手机号"  class="am-form-field" style="position: static">
        </div>
        <br>
        <div class="am-input-group">
            <span class="am-input-group-label"><i class="am-icon-lock am-icon-fw"></i></span>
            <input type="password" name="pwd" id="pwd" placeholder="密码"  class="am-form-field" style="position: static">
        </div>
        <br/>
        <input type="hidden" name="role" value="2" id="role"/>

        <div class="am-cf" style="text-align: center;">
            <input type="submit" id="sub" value="注册" class="am-btn am-btn-primary am-btn-sm wid-100 bg-1"
                   style="height: 40px;">
        </div>
        <!--</form>-->
        <hr>
    </div>
</div>
<div class="dc-alert">

</div>
</body>
<script src="__PUBLIC__/assets/js/jquery.min.js"></script>
<script>
    var regShop = function () {
        var phone = $("#phone").val();
        var pwd = $("#pwd").val();
        if (phone == '' || phone.length == 0) {
            var data = "<div class='am-alert am-alert-danger dc-div-center-alert' data-am-alert><button type='button' class='am-close'>&times;</button><p>请填写手机</p></div>"
            $(".dc-alert").append(data);
            return;
        }
        if (pwd = '' || pwd.length == 0) {
            var data = "<div class='am-alert am-alert-danger dc-div-center-alert' data-am-alert><button type='button' class='am-close'>&times;</button><p>请填写密码</p></div>"
            $(".dc-alert").append(data);
            return;
        }
        if (!phone.match(/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/)) {
            var data = "<div class='am-alert am-alert-danger dc-div-center-alert' data-am-alert><button type='button' class='am-close'>&times;</button><p>请填写正确的手机号</p></div>"
            $(".dc-alert").append(data);
            return;
        }

        $.ajax({
                    url: "{:U('User/shopRegPost')}",
                    type: 'POST',
                    data: {phone: $("#phone").val(), pwd:$("#pwd").val(), role: $("#role").val()},
                    dataType: 'json'
                })
                .always(function (res) {
                    switch (res.status) {
                        case 1002:
                            var data = "<div class='am-alert am-alert-danger dc-div-center-alert' data-am-alert><button type='button' class='am-close'>&times;</button><p>您已是商家</p></div>"
                            $(".dc-alert").append(data);
                            break;
                        case 1001:
                            window.location.href="http://f.xjwan.top/index.php/Order/order";
                            break;
                        case 1003:
                            var data = "<div class='am-alert am-alert-danger dc-div-center-alert' data-am-alert><button type='button' class='am-close'>&times;</button><p>注册失败，重新注册</p></div>"
                            $(".dc-alert").append(data);
                            break;
                        default:
                            var data = "<div class='am-alert am-alert-danger dc-div-center-alert' data-am-alert><button type='button' class='am-close'>&times;</button><p>注册错误</p></div>"
                            $(".dc-alert").append(data);
                            break;
                    }
                });
    }
    $("#sub").on("click", regShop);
    $(document).on("click", ".am-close", function () {
        $(".am-alert").hide();
    })
</script>
</html>